<template>
  <div>
    <div @keyup.enter="getData()">
      <el-form :inline="true">
        <el-form-item>
          <el-input v-model="params.customer_name" placeholder="项目名称查询" clearable></el-input>
        </el-form-item>
        <el-form-item>
          <el-input
            v-model="params.corp_name"
            placeholder="负责人查询"
            :clearable="true"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <select-address
            v-model="params.address_code"
            clearable
            placeholder="地址查询"
            :auto-top="true"
            @change="getData()"
          ></select-address>
        </el-form-item>
        <el-form-item>
          <el-button @click="getData()">查询</el-button>
        </el-form-item>
        <el-form-item>
          <el-button @click="exportExcel(fileName)" :loading="exportLoading">导出</el-button>
        </el-form-item>
      </el-form>
    </div>
    <c-table
      border
      v-loading="loading"
      :stripe="false"
      :columns="tableColumns"
      :data="tableData"
      :height="dialogHeight"
    ></c-table>

    <div class="query-pagination">
      <div></div>
      <el-pagination
        layout="total, prev, pager, next, jumper"
        :current-page.sync="params.index"
        :page-size="params.size"
        :total="totalCount"
        @current-change="getData"
      ></el-pagination>
    </div>

    <approve-edit-dialog
      :visible.sync="approveVisible"
      @success="handleEditSuccess"
      :query-id="editId"
    ></approve-edit-dialog>

    <!-- <el-dialog
      :visible.sync="reportVisible"
      :close-on-click-modal="false"
      :before-close="handleCreditClose"
      append-to-body
      top="30px"
      width="80%"
    >
      <el-tabs>
        <el-tab-pane label="数字档案卡">
          <credit-file :query-id="queryId"></credit-file>
        </el-tab-pane>
      </el-tabs>
    </el-dialog> -->

    <!-- <attach-cmpt :visible.sync="attachVisible"
                 :customer-related-id="attachRelatedId"></attach-cmpt> -->

    <el-dialog
      :visible.sync="reportEditVisible"
      :close-on-click-modal="false"
      append-to-body
      top="30px"
      width="80%"
    >
      <el-tabs v-model="activeName">
        <el-tab-pane label="立项详情" name="first">
          <approve-edit view-mode :query-id="relatedId"></approve-edit>
        </el-tab-pane>
        <el-tab-pane label="担保意向函" name="letter">
          <letter-view :query-id="relatedId"></letter-view>
        </el-tab-pane>
        <!-- <el-tab-pane label="数字档案卡" v-if="showCredit">
          <credit-file :query-id="relatedId" view-mode></credit-file>
        </el-tab-pane> -->
        <el-tab-pane label="附件">
          <attach-view :query-id="relatedId" :visible="reportEditVisible"></attach-view>
        </el-tab-pane>
      </el-tabs>
    </el-dialog>

    <new-project
      :visible.sync="newVisible"
      @success="getData()"
      :customerRelatedId="newId"
    ></new-project>
  </div>
</template>

<script>
import { enumGuatype } from '@/credit/plugins/enumTown'

import taskTableMixin from '@/credit/mixin/task/taskTable'
// import CreditFile from '@/credit/components/creditFile/CreditCard'
// import AttachCmpt from '@/credit/views/city/program/Attach'
import AttachView from '@/credit/components/AttachView'
import SelectAddress from '@/components/select/SelectAddress'
import ApproveEditDialog from '@/credit/views/county/unionProvince/components/ApproveEditDialog'
import ApproveEdit from '@/credit/views/county/unionProvince/components/ApproveEdit'
import LetterView from '@/credit/views/county/unionProvince/components/LetterView'
import NewProject from '@/credit/views/city/program/NewProject'
export default {
  components: {
    ApproveEdit,
    ApproveEditDialog, // 新省联担立项
    SelectAddress,
    // CreditFile,
    // AttachCmpt,
    AttachView,
    LetterView,
    NewProject,
  },
  mixins: [taskTableMixin],
  props: {},
  data() {
    return {
      enumGuatype,
      params: {
        index: 1,
        size: 10,
      },
      tableColumns: [
        {
          attrs: { label: '主体名称', prop: 'customer_name', minWidth: 135 },
          process: (v, row) => ({
            attrs: { class: 'project-history', attrs: { 'data-history': row.is_history } },
          }),
        },
        { attrs: { label: '地址', prop: 'address', minWidth: 135 } },
        { attrs: { label: '负责人', prop: 'corp_name', align: 'center' } },
        { attrs: { label: '联系电话', prop: 'mobile_no', align: 'center' } },
        +this.status
          ? { attrs: { label: '建议金额', prop: 'approved_funds', align: 'center' } }
          : { attrs: { label: '申请金额', prop: 'apply_funds', align: 'center' } },
        { attrs: { label: '业务类型', prop: 'project_type', align: 'center' } },
        +this.status
          ? { attrs: { label: '立项时间', prop: 'itemDate', align: 'center', width: 135 } }
          : { attrs: { label: '申请时间', prop: 'createTime', align: 'center', width: 135 } },
        {
          attrs: { label: '操作', align: 'center', width: 120 },
          operations: [
            {
              content: '修改',
              icon: 'fa fa-edit',
              event: this.handleNew,
              ifRender: row => +row.task_status === 0,
            },
            {
              content: '立项',
              icon: 'fa fa-gavel',
              event: this.handleEdit,
              ifRender: row => +row.task_status === 0,
            },
            {
              content: '查看',
              icon: 'fa fa-search',
              event: this.handleEditCredit,
              ifRender: row => +row.task_status === 1,
            },
            // {
            //   content: '档案卡',
            //   icon: 'fa fa-file-text',
            //   event: this.handleFile,
            //   ifRender: row => +row.task_status === 0 && +row.gua_type !== 4,
            //   attrs: { class: 'mx-0 px-2' },
            // },
            // { content: '附件', icon: 'fa fa-clipboard', event: this.handleAttach, attrs: { class: 'mx-0 px-2' } }
          ],
        },
      ],
      tableData: [],
      totalCount: 0,
      // tableName: 'customer_related',
      reportVisible: false,
      editId: '',
      relatedId: '',
      attachRelatedId: '',
      attachVisible: false,
      reportEditVisible: false,
      approveVisible: false,
      activeName: 'first',
      showCredit: false,
      queryId: '',
      newId: '',
      newVisible: false,
    }
  },
  computed: {
    order() {
      return +this.status ? { item_date: 'desc' } : { create_time: 'desc' }
    },
    fileName() {
      if (+this.status === 0) {
        return '未立项项目'
      } else {
        return '已立项项目'
      }
    },
  },
  watch: {},
  mounted() {},
  created() {},
  methods: {
    handleNew(row) {
      this.newVisible = true
      this.newId = row ? row.customer_related_id : ''
    },
    handleEditCredit(row) {
      this.reportEditVisible = true
      this.showCredit = +row.gua_type !== 4
      this.activeName = 'first'
      this.relatedId = row.customer_related_id
    },
    // handleAttach(row) {
    //   this.attachVisible = true
    //   this.attachRelatedId = row.customer_related_id
    // },
    handleFile(row) {
      this.queryId = row.customer_related_id
      this.reportVisible = true
    },
    handleEdit(row) {
      this.editId = row.customer_related_id || ''
      this.approveVisible = true
    },
    dataAdapter(item) {
      item.itemDate = this.$utils.dateFormat(item.item_date, this.dateFmt) || '-'
      item.createTime = this.$utils.dateFormat(item.create_time, this.dateFmt) || '-'
      item.project_type = enumGuatype[+item.gua_type] || '-'
      return item
    },
    handleEditSuccess() {
      this.$store.dispatch('getMyTaskCount')
      this.$emit('success', true)
    },
    handleCreditClose() {
      this.reportVisible = false
      this.getData(this.params.index)
    },
  },
}
</script>
<style lang="scss" scoped></style>
